package com.qf.controller;

import com.qf.entity.User;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping("/{id}")
    public User findById(@PathVariable Integer id){
        User user = new User();
        user.setName("zs");
        user.setPwd("123");
        return user;
    }

    @PostMapping
    public int add(@RequestBody User user){
        System.out.println(user);

        return 1;
    }

    @PostMapping("/test")
    public int test(String gender,Integer age,@RequestBody User user,@RequestHeader("header1") String h1,@RequestHeader("header2") String h2){
        System.out.println(gender);
        System.out.println(age);
        System.out.println(user);
        System.out.println(h1);
        System.out.println(h2);

        return 3;
    }

    @GetMapping
    public List<User> findAll(){
        //模拟后台查询用户信息
        List<User> users = new ArrayList<>();
        users.add(new User("zs1","123"));
        users.add(new User("zs2","125"));
        users.add(new User("zs3","124"));
        users.add(new User("zs4","126"));
        users.add(new User("zs5","127"));

        return users;
    }

}
